<?php
namespace Account;
class FavoriteController extends BaseController{
	/**
	 * 显示收藏夹列表
	 */
	public function index(){
		global $G,$lang;
		
		if ($this->checkFormSubmit()){
			$delete = $_GET['delete'];
			if ($delete && is_array($delete)){
				$deleteids = implodeids($delete);
				favorite_delete_data(array('uid'=>$this->uid, 'favid'=>array('IN', $deleteids)));
				$this->showSuccess('delete_succeed');
			}else {
				$this->showError('no_select');
			}
		}else {
			$type = trim($_GET['type']);
			$type = $type == 'shop' ? $type : 'goods';
			
			$pagesize = 10;
			$condition = array();
			$condition['uid'] = $this->uid;
			
			if ($type == 'goods') {
				//商品收藏
				$condition['datatype'] = 'goods';
			}else {
				//店铺收藏
				$condition['datatype'] = 'shop';
			}
			
			$totalnum = favorite_get_num($condition);
			$pagecount = $totalnum < $pagesize ? 1 : ceil($totalnum/$pagesize);
			$favoritelist = favorite_get_page($condition, $G['page'], $pagesize);
			$pages = $this->showPages($G['page'], $pagecount, $totalnum, "type=$type");
			
			$G['title'] = '我的收藏夹';
			include template('favorite');
		}
	}
	
	/**
	 * 从收藏夹删除
	 */
	public function remove(){
		$favid = intval($_GET['favid']);
		favorite_delete_data(array('uid'=>$this->uid, 'favid'=>$favid));
		$this->showAjaxReturn(array('result'=>'SUCCESS'));
	}
}